/*
 * @lc app=leetcode.cn id=1974 lang=javascript
 *
 * [1974] 使用特殊打字机键入单词的最少时间
 */

// @lc code=start
/**
 * @param {string} word
 * @return {number}
 */
var minTimeToType = function (word) {
  let pre = 'a'.charCodeAt();
  let sum = 0;
  for (let i = 0; i < word.length; i++) {
    const dis1 = Math.abs(word.charCodeAt(i) - pre);
    const dis2 = 26 - dis1;
    sum += Math.min(dis1, dis2);
    pre = word.charCodeAt(i);
  }
  return sum + word.length;
};
// @lc code=end

